package com.ruoyi.mes.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mes.domain.MtrInfo;
import com.ruoyi.mes.domain.MtrPlan;
import com.ruoyi.mes.domain.ProInfo;
import com.ruoyi.mes.mapper.MtrPlanMapper;
import com.ruoyi.mes.mapper.ProInfoMapper;
import com.ruoyi.mes.mapper.ProceInfoMapper;
import com.ruoyi.mes.service.IMtrPlanService;
import com.ruoyi.mes.service.IProInfoService;
import com.ruoyi.mes.utils.CodeUtils;
import com.ruoyi.mes.vo.plan.PlanDetailsVo;
import com.ruoyi.mes.vo.plan.ReleaseVo;
import com.ruoyi.mes.vo.product.BomMtrVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import com.ruoyi.mes.mapper.ProgPlanMapper;
import com.ruoyi.mes.domain.ProgPlan;
import com.ruoyi.mes.service.IProgPlanService;

/**
 * 生产计划Service业务层处理
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Service
public class ProgPlanServiceImpl implements IProgPlanService
{


    @Autowired
    private IProInfoService proInfoService;

    @Autowired
    private IMtrPlanService mtrPlanService; ;

    @Autowired
    private ProgPlanMapper progPlanMapper;

    /**
     * 查询生产计划
     *
     * @param id 生产计划主键
     * @return 生产计划
     */
    @Override
    public ProgPlan selectProgPlanById(Long id)
    {
        return progPlanMapper.selectProgPlanById(id);
    }

    /**
     * 查询生产计划列表
     *
     * @param progPlan 生产计划
     * @return 生产计划
     */
    @Override
    public List<ProgPlan> selectProgPlanList(ProgPlan progPlan)
    {
        List<ProgPlan> progPlans = progPlanMapper.selectProgPlanList(progPlan);
        if (progPlans.size() != 0) {
            for (ProgPlan plan : progPlans) {
                ProInfo proInfo = proInfoService.selectProInfoById(plan.getProId());
                plan.setProName(proInfo.getProName());
            }
        }
        return progPlans;
    }

    /**
     * 新增生产计划
     *
     * @param progPlan 生产计划
     * @return 结果
     */
    @Override
    public int insertProgPlan(ProgPlan progPlan)
    {
        progPlan.setCreateTime(DateUtils.getNowDate());
        return progPlanMapper.insertProgPlan(progPlan);
    }

    /**
     * 修改生产计划
     *
     * @param progPlan 生产计划
     * @return 结果
     */
    @Override
    public int updateProgPlan(ProgPlan progPlan)
    {
        progPlan.setUpdateTime(DateUtils.getNowDate());
        return progPlanMapper.updateProgPlan(progPlan);
    }

    /**
     * 批量删除生产计划
     *
     * @param ids 需要删除的生产计划主键
     * @return 结果
     */
    @Override
    public int deleteProgPlanByIds(Long[] ids)
    {
        return progPlanMapper.deleteProgPlanByIds(ids);
    }

    /**
     * 删除生产计划信息
     *
     * @param id 生产计划主键
     * @return 结果
     */
    @Override
    public int deleteProgPlanById(Long id)
    {
        return progPlanMapper.deleteProgPlanById(id);
    }



    /**
     * 计划明细
     * @param id 生产计划id
     * @return
     */
    @Override
    public PlanDetailsVo planDeatils(Long id) {
        PlanDetailsVo planDetailsVo = new PlanDetailsVo();
        ProgPlan progPlan = progPlanMapper.selectProgPlanById(id);
        planDetailsVo.setProgPlan(progPlan);
        ProInfo proInfo = proInfoService.selectProInfoById(progPlan.getProId());
        planDetailsVo.setProInfo(proInfo);
        return planDetailsVo;
    }
}
